﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace LungSoundWizard.ViewModel
{
    public class SelectTaskViewModel : WizardViewModelBase
    {
        public override string Title
        {
            get { return "Task selection"; }
        }
        
        
        RelayCommand _goAdvancedCommand;
        public ICommand GoAdvancedCommand
        {
            get
            {
                if (_goAdvancedCommand == null)
                {
                    _goAdvancedCommand = new RelayCommand(p => this.OpenAdvancedView());
                }
                return _goAdvancedCommand;
            }
        }

        public enum SelectedTasks
        {
            RecordNew, OpenExisting, EditReference, None
        }

        SelectedTasks _selectedTask = SelectedTasks.None;
        public SelectedTasks SelectedTask
        {
            get { return _selectedTask; }
            set
            {
                SetProperty(ref _selectedTask, value);

                switch (value)
                {
                    case SelectedTasks.RecordNew:
                        if (_recordNewVM == null)
                        {
                            _recordNewVM = new RecordNewViewModel(OpenExistingVM);
                        }
                        NextPage = _recordNewVM;
                        break;

                    case SelectedTasks.OpenExisting:
                        NextPage = OpenExistingVM;
                        break;

                    case SelectedTasks.EditReference:
                        NextPage = EditRefVM;
                        break;
                }
            }
        }

        private RecordNewViewModel _recordNewVM;
        private OpenExistingViewModel _openExistingVM;
        public OpenExistingViewModel OpenExistingVM
        {
            get
            {
                if (_openExistingVM == null)
                {
                    _openExistingVM = new OpenExistingViewModel();
                }

                return _openExistingVM;
            }
        }
        private EditRefSoundsViewModel _editRefVM;
        public EditRefSoundsViewModel EditRefVM
        {
            get
            {
                if (_editRefVM == null)
                {
                    _editRefVM = new EditRefSoundsViewModel();
                }

                return _editRefVM;
            }
        }

        public override bool CanGoNext
        {
            get
            {
                return SelectedTask != SelectedTasks.None;
            }
            protected set
            {
                base.CanGoNext = value;
            }
        }

        Lung_Sounds_V2.MainWindow _advWindow = null;
        void OpenAdvancedView()
        {
            if (_advWindow == null)
            {
                _advWindow = new Lung_Sounds_V2.MainWindow();
            }

            _advWindow.Show();
        }
    }
}
